package org.sxf.app.sign.handler;
import android.app.Application;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Handler;

/**
 * Created by zqc on 16/5/12.
 */
public class SignApp extends Application {

    private static SignApp instance;
    private String mVersionName;
    private String mVersionCode;
    private boolean isNetworkAvailable;
    private static Handler mHandler;
    private static long mMainThreadId;

    @Override
    public void onCreate() {
        super.onCreate();
        instance = this;
        initVersion();

        mHandler=new Handler();
        mMainThreadId = Thread.currentThread().getId();

        CrashHandlerSingleton crashHandler = CrashHandlerSingleton.getInstance();
        crashHandler.init(getApplicationContext());

    }

    public static SignApp getInstance() {
        return instance;
    }

    private void initVersion() {
        try {
            PackageManager pm = getPackageManager();
            PackageInfo pi = pm.getPackageInfo(getPackageName(), 0);
            mVersionName = pi.versionName;
            mVersionCode = String.valueOf(pi.versionCode);
        } catch (PackageManager.NameNotFoundException e) {
            mVersionName = "0.0.0";
            mVersionCode = "0";
        }
    }

    public String getVersionName() {
        if (mVersionName == null) {
            initVersion();
        }

        return mVersionName;
    }

    public String getVersionCode() {
        if (mVersionCode == null) {
            initVersion();
        }

        return mVersionCode;
    }

    public boolean isNetworkAvailable() {
        return isNetworkAvailable;
    }

    public void setNetworkAvailable(boolean isNetworkAvailable) {
        this.isNetworkAvailable = isNetworkAvailable;
    }

    public static Handler getHandler() {
        return mHandler;
    }

    public static long getMainThreadId() {
        return mMainThreadId;
    }

}